vim9script noclear

var total: list<dict<number>>
var first: number

def Date(time: number): string
	var [hour, min, sec] = [0, 0, 0]

	hour = time / 3600
	min = time % 3600 / 60
	sec = time % 60

	return printf("%02d:%02d:%02d", hour, min, sec)
enddef

export def Startup()
	first = localtime()
	total->add({'begin': first})
enddef

export def Resume()
	total->add({'begin': localtime()})
enddef

export def Suspend()
	total[-1]['end'] = localtime()
enddef

export def Show()
	var sec: number
	var time: dict<number>

	total[-1]['end'] = localtime()

	while !total->empty()
		time = total->remove(0)
		sec += time['end'] - time['begin']
	endwhile

	total[0] = {'begin': first, 'end': first + sec}
	echomsg "Coding " .. Date(sec)
enddef
